<template>
    <view class="inspect-main">
        <!-- inspect一级巡查 -->
        <!-- {{inspects}} -->
        <view v-for="(inspect, index) in inspects" :key="index">
            <view
                class="inspect-main-container"
                :class="{ 'inspect-main-container-open': inspect.open }"
                @click.native="itemShow(index)"
            >
                <view class="inspect-main-container-title">
                    {{ inspect.typeName }}
                    <span>({{ inspect.children.length }})</span>
                </view>
                <!-- inspect.checkResult(0,已巡查正常，1已巡查异常) -->
                <view
                    v-if="inspect.checkResult"
                    class="inspect-main-container-tip"
                    :class="{
                        'inspect-main-container-tip-exception':
                            inspect.checkResult == '1',
                    }"
                >
                    {{ inspect.checkResult == "0" ? "正常" : "异常" }}
                </view>
                <image
                    class="inspect-main-container-icon"
                    :src="
                        inspect.open
                            ? '/static/imgs/icon/arrow_up.png'
                            : '/static/imgs/icon/arrow_down.png'
                    "
                ></image>
            </view>
            <view v-if="inspect.open" class="inspect-main-container-content">
                <!-- inpectItem二级巡查 图片保存在辞职，bizType使用二级巡查id，fileGroup：0巡查；1复查，目前只有复查有附件 -->
                <view
                    v-for="(inpectItem, iIndex) in inspect.children"
                    :key="iIndex"
                >
                    <view
                        class="
                            inspect-main-container inspect-main-container-open
                        "
                        @click.native="itemShow(index, iIndex)"
                    >
                        <view class="inspect-main-container-title">{{
                            inpectItem.typeName
                        }}</view>
                        <!-- inpectItem.checkResultId normal表示正常 -->
                        <view
                            v-if="inpectItem.checkResultId"
                            class="inspect-main-container-tip"
                            :class="{
                                'inspect-main-container-tip-exception':
                                    inpectItem.checkResultId != 'normal',
                            }"
                        >
                            {{
                                inpectItem.checkResultId == "normal"
                                    ? "正常"
                                    : "异常"
                            }}
                        </view>
                        <image
                            class="inspect-main-container-icon"
                            :src="
                                inpectItem.open
                                    ? '/static/imgs/icon/arrow_up.png'
                                    : '/static/imgs/icon/arrow_down.png'
                            "
                        ></image>
                    </view>
                    <view v-if="inpectItem.open">
                        <view class="inspect-check-item">
                            <!-- inpectItem.checkResultId normal表示正常 -->
                            <view
                                class="inspect-check-item-content"
                                :class="{
                                    'inspect-check-item-content-select':
                                        inpectItem.checkResultId == 'normal',
                                }"
                                @click.native="
                                    checkItemClick(
                                        index,
                                        iIndex,
                                        -1,
                                        normalCheck
                                    )
                                "
                            >
                                {{ normalCheck.typeName }}
                            </view>
                            <!-- inpectItem.checkResultId normal表示正常 -->
                            <view
                                v-for="(child, cIndex) in inpectItem.children"
                                :key="cIndex"
                                class="inspect-container-main"
                            >
                                <view
                                    class="inspect-check-item-content"
                                    :class="{
                                        'inspect-check-item-content-select':
                                            inpectItem.checkResultId.indexOf(
                                                child.id
                                            ) > -1,
                                    }"
                                    @click.native="
                                        checkItemClick(
                                            index,
                                            iIndex,
                                            cIndex,
                                            child
                                        )
                                    "
                                >
                                    {{ child.typeName }}
                                </view>

                                <!-- v-if="(inspectType == 0 && inpectItem.checkResultId.indexOf(child.id) > -1 && !showInspect) || inspectType == 1" -->
                                <view
                                    v-if="
                                        (inspectType == 0 &&
                                            inpectItem.checkResultId.indexOf(
                                                child.id
                                            ) > -1) ||
                                        inspectType == 1
                                    "
                                    class="inspect-border"
                                >
                                    <!-- 2.2需求需要把巡查底部移植到此处 -->
                                    <view
                                        v-if="
                                            inspectType == 0 &&
                                            inpectItem.checkResultId.indexOf(
                                                child.id
                                            ) > -1 &&
                                            !showInspect
                                        "
                                    >
                                        <view
                                            class="
                                                inspect-main-container
                                                inspect-main-container-open-child
                                            "
                                            >上报方式</view
                                        >
                                        <view class="inspect-check-item">
                                            <view
                                                v-for="(
                                                    button, btnIndex
                                                ) in inspectButtons"
                                                :key="btnIndex"
                                                class="
                                                    inspect-check-item-content
                                                "
                                                :class="{
                                                    'inspect-check-item-content-select':
                                                        child.reportWay ==
                                                        button.value,
                                                }"
                                                @click.native="
                                                    inspectButtonClick(
                                                        index,
                                                        iIndex,
                                                        cIndex,
                                                        child,
                                                        button
                                                    )
                                                "
                                            >
                                                {{ button.name }}
                                            </view>
                                        </view>
                                        <view
                                            class="
                                                inspect-main-container
                                                inspect-main-container-open-child
                                            "
                                            v-if="child.reportWay == '1'"
                                        >
                                            现场照片（1张整改前和1张整改后）：
                                        </view>
                                        <view
                                            class="attachment-container"
                                            v-if="
                                                child.reportWay == '0' ||
                                                child.reportWay == '1' ||
                                                child.reportWay == '3'
                                            "
                                        >
                                            <view class="attachment">
                                                <view class="attribute">
                                                    <view class="asterisk"
                                                        >*</view
                                                    >
                                                    <view>
                                                        {{
                                                            child.reportWay ==
                                                            "1"
                                                                ? "整改前"
                                                                : "现场照片（1张清晰照片）"
                                                        }}
                                                    </view>
                                                </view>
                                                <view class="attachment-area">
                                                    <view
                                                        class="
                                                            attachment-area-item
                                                        "
                                                        v-for="(
                                                            item, aIndex
                                                        ) in child.eventImages"
                                                        :key="aIndex"
                                                    >
                                                        <!-- <image class="image-style" :src="item.src" @click="previewImage(child.eventImages, aIndex)">
                                                    </image> -->
                                                        <img
                                                            class="image-style"
                                                            :src="item.src"
                                                            @click="
                                                                previewImage(
                                                                    child.eventImages,
                                                                    aIndex
                                                                )
                                                            "
                                                        />
                                                        <image
                                                            v-if="!showInspect"
                                                            class="image-delete"
                                                            :src="'/static/imgs/icon/clo.png'"
                                                            @click="
                                                                deleteFile(
                                                                    index,
                                                                    iIndex,
                                                                    cIndex,
                                                                    aIndex,
                                                                    item,
                                                                    'eventImages'
                                                                )
                                                            "
                                                        >
                                                        </image>
                                                    </view>
                                                    <!-- 增加巡查纳入复查附件逻辑child.reportWay == '3' -->
                                                    <ray-pick-files
                                                        v-if="
                                                            !showInspect &&
                                                            (!child.eventImages ||
                                                                child
                                                                    .eventImages
                                                                    .length < 1)
                                                        "
                                                        :menuType="'0'"
                                                        :bizType="
                                                            child.reportWay ==
                                                            '3'
                                                                ? child.id
                                                                : 'task'
                                                        "
                                                        :fileGroup="
                                                            child.reportWay ==
                                                            '3'
                                                                ? 'czwxc'
                                                                : '0'
                                                        "
                                                        :poses="[
                                                            index,
                                                            iIndex,
                                                            cIndex,
                                                        ]"
                                                        @fileEventPickedChange="
                                                            fileEventPickedChange
                                                        "
                                                        :filePicked="'fileEventPickedChange'"
                                                    >
                                                    </ray-pick-files>
                                                </view>
                                            </view>
                                            <view
                                                class="attachment"
                                                v-if="child.reportWay == '1'"
                                            >
                                                <view class="attribute">
                                                    <view class="asterisk"
                                                        >*</view
                                                    >
                                                    <view>整改后</view>
                                                </view>
                                                <view class="attachment-area">
                                                    <view
                                                        class="
                                                            attachment-area-item
                                                        "
                                                        v-for="(
                                                            item, aIndex
                                                        ) in child.eventRectifyImages"
                                                        :key="aIndex"
                                                    >
                                                        <!-- <image class="image-style" :src="item.src" @click="previewImage(child.eventRectifyImages, aIndex)">
                                                    </image> -->
                                                        <img
                                                            class="image-style"
                                                            :src="item.src"
                                                            @click="
                                                                previewImage(
                                                                    child.eventRectifyImages,
                                                                    aIndex
                                                                )
                                                            "
                                                        />
                                                        <image
                                                            v-if="!showInspect"
                                                            class="image-delete"
                                                            :src="'/static/imgs/icon/clo.png'"
                                                            @click="
                                                                deleteFile(
                                                                    index,
                                                                    iIndex,
                                                                    cIndex,
                                                                    aIndex,
                                                                    item,
                                                                    'eventRectifyImages'
                                                                )
                                                            "
                                                        >
                                                        </image>
                                                    </view>
                                                    <ray-pick-files
                                                        v-if="
                                                            !showInspect &&
                                                            (!child.eventRectifyImages ||
                                                                child.eventRectifyImages .length < 1)
                                                        "
                                                        :menuType="'0'"
                                                        :bizType="'task'"
                                                        :fileGroup="'jcjb_after'"
                                                        :poses="[
                                                            index,
                                                            iIndex,
                                                            cIndex,
                                                        ]"
                                                        @fileEventRectifyPickedChange="
                                                            fileEventRectifyPickedChange
                                                        "
                                                        :filePicked="'fileEventRectifyPickedChange'"
                                                    >
                                                    </ray-pick-files>
                                                </view>
                                            </view>
                                        </view>
                                        <textarea
                                            class="text-area-s"
                                            v-if="child.reportWay"
                                            v-model="child.remark"
                                            :placeholder="'备注'"
                                            maxlength="500"
                                        >
                                        </textarea>
                                    </view>

                                    <!--巡查数据回显 -->
                                    <view
                                        v-if="
                                            child.showInspectImages &&
                                            child.showInspectImages.length > 0
                                        "
                                    >
                                        <view class="attachment">
                                            <view class="attribute">
                                                <!-- <view>{{child.reportWay=="1" ? "处置前照片" : "现场照片"}}</view> -->
                                                <view>现场照片</view>
                                            </view>
                                            <view class="attachment-area">
                                                <view
                                                    class="attachment-area-item"
                                                    v-for="(
                                                        item, showImageIndex
                                                    ) in child.showInspectImages"
                                                    :key="showImageIndex"
                                                >
                                                    <image
                                                        class="image-style"
                                                        :src="item.filepath"
                                                        @click="
                                                            previewNetImage(
                                                                child.showInspectImages,
                                                                showImageIndex
                                                            )
                                                        "
                                                    />
                                                </view>
                                            </view>
                                        </view>
                                        <!-- 如果是即采即办事件就显示  当提交的隐患项是即采即办时 showInspectAfterImages才存在-->
                                        <view v-if="child.showInspectAfterImages && child.showInspectImages.length > 0" class="attachment">
                                            <view class="attribute">
                                                <view>处置后图片</view>
                                            </view>
                                            <view class="attachment-area">
                                                <view
                                                    class="attachment-area-item"
                                                    v-for="(
                                                        item, showImageIndex
                                                    ) in child.showInspectAfterImages"
                                                    :key="showImageIndex"
                                                >
                                                    <image
                                                        class="image-style"
                                                        :src="item.filepath"
                                                        @click="
                                                            previewNetImage(
                                                                child.showInspectAfterImages,
                                                                showImageIndex
                                                            )
                                                        "
                                                    />
                                                </view>
                                            </view>
                                        </view>
                                        <textarea
                                            class="text-area-s"
                                            v-if="child.showRemark"
                                            :disabled="true"
                                            v-model="child.showRemark"
                                            :placeholder="'备注'"
                                            maxlength="500"
                                        >
                                        </textarea>
                                    </view>

                                    <!-- 2.2需求需要把巡查底部移植到此处 -->
                                    <view v-if="inspectType == 1">
                                        <view
                                            class="
                                                inspect-main-container
                                                inspect-main-container-open-child
                                            "
                                            >现场整改</view
                                        >
                                        <view class="inspect-check-item">
                                            <!-- child.isReviewChange复查整改 -->
                                            <view
                                                v-for="(
                                                    rectify, rIndex
                                                ) in rectifies"
                                                :key="rIndex"
                                                class="
                                                    inspect-check-item-content
                                                "
                                                :class="{
                                                    'inspect-check-item-content-select':
                                                        child.isReviewChange ==
                                                        rectify.value,
                                                }"
                                                @click.native="
                                                    rectifyCheck(
                                                        index,
                                                        iIndex,
                                                        cIndex,
                                                        child,
                                                        rectify
                                                    )
                                                "
                                            >
                                                {{ rectify.name }}
                                            </view>
                                        </view>
                                        <view class="attachment">
                                            <!-- <view class="attribute">
                                            <view class="asterisk">*</view>
                                            <view>现场图片</view>
                                        </view> -->
                                            <view class="attachment-area">
                                                <view
                                                    class="attachment-area-item"
                                                    v-for="(
                                                        item, aIndex
                                                    ) in child.imageList"
                                                    :key="aIndex"
                                                >
                                                    <!-- <image class="image-style" :src="item.src" @click="previewImage(child.imageList, aIndex)">
                                                </image> -->
                                                    <img
                                                        class="image-style"
                                                        :src="item.src"
                                                        @click="
                                                            previewImage(
                                                                child.imageList,
                                                                aIndex
                                                            )
                                                        "
                                                    />
                                                    <image
                                                        v-if="!showInspect"
                                                        class="image-delete"
                                                        :src="'/static/imgs/icon/clo.png'"
                                                        @click="
                                                            deleteFile(
                                                                index,
                                                                iIndex,
                                                                cIndex,
                                                                aIndex,
                                                                item,
                                                                'imageList'
                                                            )
                                                        "
                                                    >
                                                    </image>
                                                </view>
                                                <!-- <view class="attachment-area-item" v-for="(item, index) in child.fileList"
                                                :v-bind:key="index" :key="index">
                                                <image class="image-style" :src="'/static/imgs/icon/clo.png'">
                                                </image>
                                                <image class="image-delete"
                                                    src="/static/imgs/icon/clo.png"
                                                    @click="deleteFile(1, item)">
                                                </image>
                                            </view> -->
                                                <!-- fileGroup原来为1，现修改复查时为0，修复服务端上报事件无附件问题 modify by ray on 2021/01/11 -->
                                                <ray-pick-files
                                                    v-if="
                                                        !showInspect &&
                                                        (!child.imageList ||
                                                            child.imageList
                                                                .length < 2)
                                                    "
                                                    :menuType="'0'"
                                                    :bizType="child.id"
                                                    :fileGroup="'0'"
                                                    :poses="[
                                                        index,
                                                        iIndex,
                                                        cIndex,
                                                    ]"
                                                    @filePickedChange="
                                                        filePickedChange
                                                    "
                                                    :filePicked="'filePickedChange'"
                                                >
                                                </ray-pick-files>

                                                <!-- <view v-if="imagePaths[1].length < 4 && editEnable"
                                                class="attachment-area-item attachment-area-item-center"
                                                @click="chooseImage(1)"
                                                >
                                                <image class="image-add" :src="'/static/imgs/icon/clo.png'">
                                                </image>
                                            </view> -->
                                            </view>
                                        </view>
                                        <textarea
                                            class="text-area-s"
                                            v-model="child.remark"
                                            :placeholder="'备注'"
                                            maxlength="500"
                                        >
                                        </textarea>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import Vue from "vue";
import { RayPickFiles } from "@/components/ray-pick-files/ray-pick-files.vue";
import { createUUID } from "@/utils/createUUID";
import { fileUrl } from "../../../api/config.js";
/**
 * 附件问题说明，详细参照ray-pick-files组件里的配置
 * 1.巡查附件，附件bizId=巡查异常里的eventId，bizType=巡查异常项id，fileGroup=czwxc
 * 2.复查附件，附件bizId=巡查异常里的fileId，bizType=巡查异常项id，fileGroup=0
 * 一般事件和即采即办事件
 * 1.处置前附件，附件bizId=巡查异常里的eventId，bizType=task，fileGroup=0
 * 2.处置后附件，附件bizId=巡查异常里的eventId，bizType=task，fileGroup=jcjb_after
 */

export default {
    name: "ray-inspect",
    components: {
        RayPickFiles,
    },
    props: {
        /**
         * 显示检查json，复查和显示时必填
         */
        inspectJson: {
            type: String,
            default() {
                return "";
            },
        },
        /**
         * 显示时禁用，默认时非显示
         */
        showInspect: {
            type: Boolean,
            default: false,
        },

        /**
         * 回调函数方法名，默认为inspectSelected
         */
        inspectSelected: {
            type: String,
            default() {
                return "inspectSelected";
            },
        },

        /**
         * 巡查项类型
         */
        inspectItemType: {
            type: [String, Number],
            default() {
                return "";
            },
        },

        /**
         * 巡查类型
         * 0巡查，1复查
         */
        inspectType: {
            type: [String, Number],
            default() {
                return 0;
            },
        },
    },
    components: {},
    data() {
        return {
            // 巡查点击菜单
            menus: [
                {
                    name: "待复查",
                    value: "1001",
                },
                {
                    name: "事件上报",
                    value: "1002",
                },
            ],
            /**
                 * 巡查点击菜单
                 * 一般事件 0
                   即采即办 1
                   紧急事件 2
                   纳入复查 3
                   正常 ：不用传值 空值
                 */
            inspectButtons: [
                {
                    name: "即采即办",
                    value: "1",
                },
                {
                    name: "纳入复查",
                    value: "3",
                },
                {
                    name: "事件上报",
                    value: "0",
                },
            ],
            // 原始数据巡查项
            originInpects: [],
            // 处理后的巡查项，可以是巡查，也可以是复查 checkResult(0,已巡查正常，1已巡查异常) checkResultId
            inspects: [],

            // 正常选项
            normalCheck: {
                id: "normal",
                typeName: "正常",
            },

            // 复查
            rectifies: [
                {
                    name: "已整改",
                    value: "1",
                },
                {
                    name: "未整改",
                    value: "0",
                },
            ],
            // 点击选中的巡查内容，巡查时使用；保存三级项
            chooses: [],
        };
    },
    onLoad() {},
    watch: {
        inspectItemType(newVal, oldVal) {
            let __this = this;
            if (newVal != oldVal) {
                __this.init();
            }
        },
        inspectJson(newVal, oldVal) {
            let __this = this;
            if (newVal != oldVal) {
                __this.init();
            }
        },
    },
    created() {
        this.init();
    },
    onShow() {},
    methods: {
        init() {
            let __this = this;
            __this.inspects = [];
            if (!this.inspectItemType) {
                // uni.showToast({
                // 	title: '请设置巡查项类别',
                // 	icon: 'none'
                // });
                return;
            } else {
                this.originInpects = this.$store.state.inspectItems;

                let showObj = "";
                if (this.inspectJson) {
                    showObj = JSON.parse(this.inspectJson);
                }
                //inspectType 巡查类型 0 巡查 1复查
                if (this.inspectType && this.inspectType == "1") {
                    // 复查内容
                    if (!this.inspectJson) {
                        // uni.showToast({
                        // 	title: '请设置复查内容',
                        // 	icon: 'none'
                        // });
                        return;
                    }
                }
                
                //originInpects 根据单元用途inspectItemType 来筛选 巡查项
                this.originInpects = this.originInpects.filter(function (item) {
                    return item.id == __this.inspectItemType;
                });
                if (this.originInpects.length > 0) {
                    if (!this.inspectJson) {
                        let insPectClickData =
                            this.$store.state.insPectClickData;

                        if (
                            this.insPectClickData &&
                            this.insPectClickData.length > 0
                        ) {
                            this.inspects = JSON.parse(
                                JSON.stringify(insPectClickData)
                            );
                            return;
                        }

                        this.inspects = JSON.parse(
                            JSON.stringify(this.originInpects[0].children)
                        );

                        // 默认选中正常
                        let list = this.inspects;
                        list.forEach((item, index) => {
                            if (!!item.children && item.children.length > 0) {
                                let children = item.children;
                                children.forEach((item1, iIndex) => {
                                    this.checkItemClick(index, iIndex, -1, {
                                        id: "normal",
                                        typeName: "正常",
                                    });
                                });
                            }
                        });
                    } else {
                        // console.log("inspectJson", this.inspectJson);

                        let dics = JSON.parse(
                            JSON.stringify(this.originInpects[0].children)
                        );
                        //debugger
                        dics.forEach((parentDic) => {
                            let abs = showObj.filter((showFilter) => {
                                return showFilter.key == parentDic.id;
                            });

                            // console.log(JSON.stringify(parentDic));
                            // console.log(JSON.stringify(abs[0]));
                            // console.log(abs[0]);
                            let childrens = [];
                            parentDic.children.forEach((childDic) => {
                                // console.log(childDic);
                                abs[0].abnormals.forEach((abnormal) => {
                                    // console.log(childDic.typeName);
                                    if (
                                        childDic.id == abnormal.dangerTypeCode
                                    ) {
                                        // debugger
                                        // 隐患，并且纳入复查
                                        if (
                                            abnormal.isDanger == "1"
                                            // &&
                                            // abnormal.reportWay == "3"
                                        ) {
                                            //如果是巡查，就把所有隐患项展示出来
                                            if(__this.inspectType=="0"){
                                            parentDic.checkResult = "1";
                                            if (!childDic.checkResultId) {
                                                childDic.checkResultId = "";
                                            }
                                            childDic.checkResultId +=
                                                (childDic.checkResultId
                                                    ? ","
                                                    : "") +
                                                abnormal.itemDetailsId;
                                            // 服务端要新增复查任务id add by ray on 2021/01/08
                                            for (
                                                let i = 0;
                                                i < childDic.children.length;
                                                i++
                                            ) {
                                                let itemChild =
                                                    childDic.children[i];
                                                if (
                                                    itemChild.id ==
                                                    abnormal.itemDetailsId
                                                ) {
                                                    itemChild.reviewCheckId =
                                                        abnormal.reviewCheckId;
                                                    if (abnormal.remark) {
                                                        // itemChild.remark = abnormal.remark;
                                                        itemChild.showRemark =
                                                            abnormal.remark;
                                                    }
                                                    if (abnormal.eventId) {
                                                        itemChild.eventId =
                                                            abnormal.eventId;
                                                    }
                                                    if (abnormal.fileId) {
                                                        itemChild.fileId =
                                                            abnormal.fileId;
                                                    }
                                                    break;
                                                }
                                            }
                                            let chs = childrens.filter((ch) => {
                                                return ch.id == childDic.id;
                                            });
                                            // console.log(chs.length);
                                            if (chs.length == 0) {
                                                childrens.push(childDic);
                                            }
                                            }
                                            //如果是复查，就判断上报方式是否为纳入复查，只展示纳入复查的巡查项
                                            if(__this.inspectType=="1" && abnormal.reportWay == "3"){
                                                parentDic.checkResult = "1";
                                                if (!childDic.checkResultId) {
                                                    childDic.checkResultId = "";
                                                }
                                                childDic.checkResultId +=
                                                    (childDic.checkResultId
                                                        ? ","
                                                        : "") +
                                                    abnormal.itemDetailsId;
                                                // 服务端要新增复查任务id add by ray on 2021/01/08
                                                for (
                                                    let i = 0;
                                                    i < childDic.children.length;
                                                    i++
                                                ) {
                                                    let itemChild =
                                                        childDic.children[i];
                                                    if (
                                                        itemChild.id ==
                                                        abnormal.itemDetailsId
                                                    ) {
                                                        itemChild.reviewCheckId =
                                                            abnormal.reviewCheckId;
                                                        if (abnormal.remark) {
                                                            // itemChild.remark = abnormal.remark;
                                                            itemChild.showRemark =
                                                                abnormal.remark;
                                                        }
                                                        if (abnormal.eventId) {
                                                            itemChild.eventId =
                                                                abnormal.eventId;
                                                        }
                                                        if (abnormal.fileId) {
                                                            itemChild.fileId =
                                                                abnormal.fileId;
                                                        }
                                                        break;
                                                    }
                                                }
                                                let chs = childrens.filter((ch) => {
                                                    return ch.id == childDic.id;
                                                });
                                                // console.log(chs.length);
                                                if (chs.length == 0) {
                                                    childrens.push(childDic);
                                                }
                                            }
                                            // console.log(childrens);
                                        }
                                    }
                                });
                                if (
                                    this.inspectType != "1" &&
                                    !childDic.checkResultId
                                ) {
                                    childDic.checkResultId = "normal";
                                    let chs = childrens.filter((ch) => {
                                        return ch.id == childDic.id;
                                    });
                                    // console.log(chs.length);
                                    if (chs.length == 0) {
                                        childrens.push(childDic);
                                    }
                                }
                            });
                            let temp = JSON.parse(JSON.stringify(parentDic));
                            if (childrens.length > 0) {
                                temp.children = childrens;
                            }
                            this.inspects.push(temp);
                        });

                        if (this.inspectType == "1") {
                            this.inspects = this.inspects.filter((item) => {
                                return (
                                    item.checkResult && item.checkResult == "1"
                                );
                            });
                        }
                        // debugger
                        //数据回显逻辑
                        
                        for (let i = 0; i < this.inspects.length; i++) {
                            let ins = this.inspects[i];
                            for (let j = 0; j < ins.children.length; j++) {
                                let insChild = ins.children[j];
                                for (
                                    let k = 0;
                                    k < insChild.children.length;
                                    k++
                                ) {
                                    let child = insChild.children[k];
                                    if (
                                        insChild.checkResultId &&
                                        insChild.checkResultId.indexOf(
                                            child.id
                                        ) > -1
                                    ) {
                                        
                                        // this.attachments(
                                        //     child.eventId,
                                        //     child.id,
                                        //     czwxc,
                                        //     [i, j, k],
                                        //     "showInspectImages"
                                        // );
                                        //TODO附件请求逻辑修改:之前固定取fileGroup:czwxc的附件,
                                        //现在通过判断reportWay是否为3(复查任务),如果为3,则fileGroup:czwxc,如果不为3,则fileGroup:0。
                                        dics.forEach((parentDic) => {
                                            let abs = showObj.filter(
                                                (showFilter) => {
                                                    return (
                                                        showFilter.key ==
                                                        parentDic.id
                                                    );
                                                }
                                            );
                                            let childrens = [];
                                            parentDic.children.forEach(
                                                (childDic) => {
                                                    // console.log(childDic);
                                                    abs[0].abnormals.forEach(
                                                        (abnormal) => {
                                                            // console.log(childDic.typeName);
                                                            if (
                                                                childDic.id ==
                                                                abnormal.dangerTypeCode
                                                            ) {
                                                                // console.log("abnormal",abnormal)
                                                                if (
                                                                    abnormal.reportWay
                                                                ) {
                                                                    // console.log(
                                                                    //     "打印reportWay",
                                                                    //     abnormal
                                                                    // );
                                                                    this.attachments(
                                                                        child.eventId,
                                                                        abnormal.reportWay == "3" ? child.id   : "task",
                                                                        abnormal.reportWay == "3" ? "czwxc" : "0",
                                                                        [ i, j, k,],
                                                                        "showInspectImages"
                                                                    );
                                                                    //如果上报方式为 即采即办,再取这个处理后的文件。
                                                                    if(abnormal.reportWay == '1'){
                                                                        this.attachments(
                                                                            child.eventId,
                                                                            "task",
                                                                            "jcjb_after",
                                                                            [ i, j, k,],
                                                                            "showInspectAfterImages"
                                                                    );
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    );
                                                }
                                            );
                                        });
                                    } else {
                                        //如果是复查,且没有提交该选项,在异常项数组中删除
                                        if(__this.inspectType=="1"){
                                            Vue.delete(insChild.children, k);
                                        }
                                        
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        /**
         * 取附件
         * @param {Object} bizId
         * @param {Object} bizType
         * @param {Object} fileGroup
         * @param {Object} pos 数组
         * @param {Object} key 要往对象里加的key名
         */
        attachments(bizId, bizType, fileGroup, pos, key) {
            let __this = this;
            this.$api
                .attachments({
                    // 'accessToken': this.$store.state.loginData.accessToken,
                    bizId: bizId,
                    bizType: bizType,
                    fileGroup: fileGroup,
                    pageNumber: "1",
                    pageSize: "10",
                })
                .then((resp) => {
                    if (resp.state) {
                        if (resp.data.length) {
                            resp.data.forEach((item) => {
                                item.filepath = fileUrl + "/" + item.filepath;
                            });
                            Vue.set(
                                __this.inspects[pos[0]].children[pos[1]]
                                    .children[pos[2]],
                                key,
                                resp.data
                            );
                            console.log(
                                "附件数组",
                                __this.inspects[pos[0]].children[pos[1]]
                                    .children[pos[2]].showInspectImages
                            );
                            // debugger
                        }
                    }
                });
        },

        /**
         * 巡查项展开
         * @param {Object} inspectIndex 一级目录位置
         * @param {Object} inspectItemIndex 二级目录位置
         */
        itemShow(inspectIndex, inspectItemIndex) {
            if (inspectItemIndex != undefined) {
                // 二级目录展开
                let open = "";
                if (
                    this.inspects[inspectIndex].children[inspectItemIndex].open
                ) {
                    open =
                        !this.inspects[inspectIndex].children[inspectItemIndex]
                            .open;
                } else {
                    open = true;
                }
                Vue.set(
                    this.inspects[inspectIndex].children[inspectItemIndex],
                    "open",
                    open
                );
            } else {
                // 一级目录展开
                let open = "";
                if (this.inspects[inspectIndex].open) {
                    open = !this.inspects[inspectIndex].open;
                } else {
                    open = true;
                }
                Vue.set(this.inspects[inspectIndex], "open", open);
            }
        },

        cancelPop() {
            this.chooses = [];
            this.$refs.popupCheck.close();
        },

        popChange(val) {
            if (!val.show) {
                this.chooses = [];
            }
        },

        /**
         * 巡查项插入值
         * add by ray on 2021/01/21
         */
        insertParamsToInspectItem(positions, key, value) {
            let __this = this;
            let arr = JSON.parse(positions);
            // console.log(arr.length);
            // console.log(key);
            // console.log(value);
            if (arr && arr.length > 0) {
                if (arr.length == 1) {
                    if (key && value) {
                        Vue.set(__this.inspects[arr[0]], key, value);
                    }
                } else if (arr.length == 2) {
                    if (key && value) {
                        Vue.set(
                            __this.inspects[arr[0]].children[arr[1]],
                            key,
                            value
                        );
                    }
                } else if (arr.length == 3) {
                    if (key && value) {
                        Vue.set(
                            __this.inspects[arr[0]].children[arr[1]].children[
                                arr[2]
                            ],
                            key,
                            value
                        );
                    }
                }
            }
        },

        /**
         * 2.1巡查事件功能
         * @param {Object} index
         * @param {Object} iIndex
         * @param {Object} cIndex
         * @param {Object} inpectItem
         * @param {Object} button
         */
        inspectButtonClick(index, iIndex, cIndex, inpectItem, button) {
            let __this = this;
            // console.log("------------inspectButtonClick");
            // console.log(((__this.inspects[index].children)[iIndex].children)[cIndex].reportWay);
            /**
                    一般事件 0
                    即采即办 1
                    紧急事件 2
                    纳入复查 3
                    正常 ：不用传值，空值
                 */
            Vue.set(
                __this.inspects[index].children[iIndex].children[cIndex],
                "reportWay",
                button.value
            );
        },

        /**
         * 巡查选项点击
         * @param {Object} inspectIndex 一级目录位置
         * @param {Object} inspectItemIndex 二级目录位置
         * @param {Object} checkItem 选中内容
         */
        checkItemClick(
            inspectIndex,
            inspectItemIndex,
            checkIndex,
            checkItem,
            isFromLocal
        ) {
            if (this.showInspect || this.inspectType == "1") {
                return;
            }
            let __this = this;
            if (checkItem && checkItem.id == "normal") {
                // 选中正常
                Vue.set(
                    __this.inspects[inspectIndex].children[inspectItemIndex],
                    "checkResultId",
                    checkItem.id
                );

                let pa = __this.inspects[inspectIndex].children.filter(
                    (item) => {
                        return (
                            item.checkResultId &&
                            item.checkResultId != checkItem.id
                        );
                    }
                );

                Vue.set(
                    __this.inspects[inspectIndex],
                    "checkResult",
                    pa.length > 0 ? "1" : "0"
                );

                if (this.inspectType == "0") {
                    // 巡查正常
                } else {
                    // 复查异常
                }
            } else {
                __this.chooses = [inspectIndex, inspectItemIndex, checkIndex];

                // 选中异常
                if (__this.inspectType == "0") {
                    // 异常巡查

                    // 2.1需求，不通过弹框选取
                    // __this.$refs.popupCheck.open();

                    Vue.set(
                        __this.inspects[__this.chooses[0]],
                        "checkResult",
                        "1"
                    );

                    // // 单选异常内容
                    // Vue.set((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]],
                    //     "checkResultId", (((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]]).id);
                    // Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
                    //     "isCheck", "1");

                    // -----------多选功能start-----------
                    // 2.1新需求，多选异常 modify by ray on 2021/05.19
                    let ids = "";
                    let abnormalContent =
                        __this.inspects[__this.chooses[0]].children[
                            __this.chooses[1]
                        ].checkResultId;
                    let nowCheckId =
                        __this.inspects[__this.chooses[0]].children[
                            __this.chooses[1]
                        ].children[__this.chooses[2]].id;
                    // console.log(abnormalContent);
                    // console.log("-----------");
                    // console.log(nowCheckId);
                    if (abnormalContent == "normal") {
                        abnormalContent = "";
                    }
                    if (abnormalContent.indexOf(nowCheckId) > -1) {
                        let abnormalArray = abnormalContent.split(",");
                        abnormalArray.forEach((item) => {
                            if (item != nowCheckId) {
                                ids += (ids.length > 0 ? "," : "") + item;
                            } else {
                                Vue.set(
                                    __this.inspects[__this.chooses[0]].children[
                                        __this.chooses[1]
                                    ].children[__this.chooses[2]],
                                    "reportWay",
                                    ""
                                );
                            }
                        });
                    } else {
                        ids = abnormalContent;
                        ids += (ids.length > 0 ? "," : "") + nowCheckId;
                        console.log(ids);
                        if (!checkItem.reportWay) {
                            Vue.set(
                                __this.inspects[__this.chooses[0]].children[
                                    __this.chooses[1]
                                ].children[__this.chooses[2]],
                                "reportWay",
                                ""
                            );
                        }
                    }
                    // 如果取消了所有的异常，则设置为正常
                    if (!ids) {
                        ids = "normal";
                        // Vue.set((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]],
                        //     "reportWay", "");
                        // Vue.set(((__this.inspects[__this.chooses[0]].children)[__this.chooses[1]].children)[__this.chooses[2]],
                        //     "reportWay", "");
                        Vue.set(
                            __this.inspects[__this.chooses[0]].children[
                                __this.chooses[1]
                            ].children[__this.chooses[2]],
                            "reportWay",
                            ""
                        );
                    }
                    Vue.set(
                        __this.inspects[__this.chooses[0]].children[
                            __this.chooses[1]
                        ],
                        "checkResultId",
                        ids
                    );
                    let pa = __this.inspects[inspectIndex].children.filter(
                        (item) => {
                            return (
                                item.checkResultId &&
                                item.checkResultId != "normal"
                            );
                        }
                    );
                    Vue.set(
                        __this.inspects[inspectIndex],
                        "checkResult",
                        pa.length > 0 ? "1" : "0"
                    );
                    // -----------多选功能end-----------

                    // if (!isFromLocal || isFromLocal == false) {
                    // 	//将选中的数据缓存
                    // 	let item = {
                    // 		inspectIndex: inspectIndex,
                    // 		inspectItemIndex: inspectItemIndex,
                    // 		checkIndex: checkIndex,
                    // 		checkItem: checkItem
                    // 	}
                    // 	let insPectClickData = this.$store.state.insPectClickData;
                    // 	if (insPectClickData.length == 0) {
                    // 		insPectClickData.push(item)
                    // 		this.$store.commit('updateInsPectClickData', insPectClickData)
                    // 	} else {
                    // 		let isIn = false;
                    // 		for (let i of insPectClickData) {
                    // 			if (i.inspectIndex == inspectIndex && i.inspectItemIndex == inspectItemIndex &&
                    // 				i.checkIndex == checkIndex && i.checkItem.id == checkItem.id) {
                    // 				isIn = true
                    // 				break;
                    // 			}
                    // 		}
                    // 		if (isIn == false) {
                    // 			//之前不存在
                    // 			insPectClickData.push(item)
                    // 			this.$store.commit('updateInsPectClickData', insPectClickData)
                    // 		}

                    // 	}
                    // 	__this.$refs.popupCheck.open();
                    // } else {}
                } else {
                    // 异常复查
                    Vue.set(
                        __this.inspects[__this.chooses[0]],
                        "checkResult",
                        "1"
                    );
                    // 单选异常内容
                    Vue.set(
                        __this.inspects[__this.chooses[0]].children[
                            __this.chooses[1]
                        ],
                        "checkResultId",
                        __this.inspects[__this.chooses[0]].children[
                            __this.chooses[1]
                        ].children[__this.chooses[2]].id
                    );
                    Vue.set(
                        __this.inspects[__this.chooses[0]].children[
                            __this.chooses[1]
                        ].children[__this.chooses[2]],
                        "isCheck",
                        "1"
                    );
                }
            }
        },

        /**
         * 复查整改选择
         * @param {Object} inspectIndex 一级目录位置
         * @param {Object} inspectItemIndex 二级目录位置
         * @param {Object} inspectItemChildIndex 三级级目录位置
         * @param {Object} inspectItem
         */
        rectifyCheck(
            inspectIndex,
            inspectItemIndex,
            inspectItemChildIndex,
            inspectItem,
            recify
        ) {
            let __this = this;
            console.log(recify);
            console.log(__this.inspects[inspectIndex]);
            console.log(
                __this.inspects[inspectIndex].children[inspectItemIndex]
            );
            Vue.set(
                __this.inspects[inspectIndex].children[inspectItemIndex]
                    .children[inspectItemChildIndex],
                "isReviewChange",
                recify.value
            );
        },

        /**
         * @description:value 改变时触发 change 事件
         * @author ray
         */
        bindChange(data) {
            this.$store.commit("updateInsPectClickData", this.inspects);
            this.$emit(this.inspectSelected, data);
        },

        /**
         * 巡查-事件附件选取回调
         * @param {Object} val
         */
        fileEventPickedChange(val) {
            let __this = this;
            console.log('事件附件选取回调',val);
            let files =
                __this.inspects[val.poses[0]].children[val.poses[1]].children[
                    val.poses[2]
                ].eventImages;
            if (!files) {
                files = [];
            }
            files.push(val);
            Vue.set(
                __this.inspects[val.poses[0]].children[val.poses[1]].children[
                    val.poses[2]
                ],
                "eventImages",
                files
            );
        },

        /**
         * 巡查-事件-处置后附件选取回调
         * @param {Object} val
         */
        fileEventRectifyPickedChange(val) {
            let __this = this;
            console.log('处置后附件选取回调',val);
            let files =
                __this.inspects[val.poses[0]].children[val.poses[1]].children[
                    val.poses[2]
                ].eventRectifyImages;
            if (!files) {
                files = [];
            }
            files.push(val);

            Vue.set(
                __this.inspects[val.poses[0]].children[val.poses[1]].children[
                    val.poses[2]
                ],
                "eventRectifyImages",
                files
            );
        },

        /**
         * 复查附件选取回调
         * @param {Object} val
         */
        filePickedChange(val) {
            let __this = this;
            console.log('复查附件选取回调',val);
            let files =
                __this.inspects[val.poses[0]].children[val.poses[1]].children[
                    val.poses[2]
                ].imageList;
            if (!files) {
                files = [];
            }
            files.push(val);

            Vue.set(
                __this.inspects[val.poses[0]].children[val.poses[1]].children[
                    val.poses[2]
                ],
                "imageList",
                files
            );
        },

        /**
         * 删除附件
         * @param {Object} index 1级巡查项pos
         * @param {Object} iIndex 2级巡查项pos
         * @param {Object} cIndex 3级巡查项pos
         * @param {Object} aIndex 附件pos
         * @param {Object} item 附件内容
         * @param {Object} key 附件所属键值key
         */
        deleteFile(index, iIndex, cIndex, aIndex, item, key) {
            let _this = this;
            uni.showModal({
                title: "提示",
                content: "确定要删除该文件吗",
                success: function (res) {
                    if (res.confirm) {
                        console.log("用户点击确定");
                        // fileType, image/auido/video
                        if (item.fileType == "image") {
                            let images =
                                _this.inspects[index].children[iIndex].children[
                                    cIndex
                                ][key];
                            images.some((t, i) => {
                                if (t.src == item.src) {
                                    images.splice(i, 1);
                                    // 在数组的some方法中，如果return true，就会立即终止这个数组的后续循环,所以相比较foreach，如果想要终止循环，那么建议使用some
                                    return true;
                                }
                            });
                            Vue.set(
                                _this.inspects[index].children[iIndex].children[
                                    cIndex
                                ],
                                key,
                                images
                            );
                        }

                        // let deleteParams = [ item.systemid ];
                        // _this.$api.attachmentDel(JSON.stringify([item.systemid])).then(
                        //     resp => {
                        //         if (resp.state){
                        //             uni.showToast({
                        //             	title: '删除成功！',
                        //             	icon: 'none'
                        //             });
                        //             // _this.imagePaths[pos] = (_this.imagePaths[pos]).filter(t => t.systemid != item.systemid);
                        //             _this.imagePaths[pos].some((t, i) => {
                        //             	if (t.systemid == item.systemid ){
                        //             		_this.imagePaths[pos].splice(i, 1);
                        //             		// 在数组的some方法中，如果return true，就会立即终止这个数组的后续循环,所以相比较foreach，如果想要终止循环，那么建议使用some
                        //             		return true;
                        //                 }
                        //             });
                        //         }
                        //     }
                        // );
                    } else if (res.cancel) {
                        console.log("用户点击取消");
                    }
                },
            });
        },

        /**
         * 网络图片预览
         */
        previewNetImage(arrayList, index) {
            let paths = [];
            console.log(arrayList, index);
            arrayList.forEach((item) => {
                paths.push(item.filepath);
            });
            // 预览图片
            uni.previewImage({
                urls: paths,
                current: index,
                // 图片指示器样式，可取值："default" - 底部圆点指示器； "number" - 顶部数字指示器； "none" - 不显示指示器。
                indicator: "default",
            });
        },

        /**
         * 本地图片预览
         */
        previewImage(arrayList, index) {
            return;
            let paths = [];
            console.log(arrayList, index);
            arrayList.forEach((item) => {
                paths.push(item.src);
            });
            // 预览图片
            uni.previewImage({
                urls: paths,
                current: index,
                // 图片指示器样式，可取值："default" - 底部圆点指示器； "number" - 顶部数字指示器； "none" - 不显示指示器。
                indicator: "default",
            });
        },

        /**
         * 组件提交初始化
         */
        validateSubmit() {
            let __this = this;
            let ins = __this.inspects;
            if (!ins || ins.length == 0) {
                return;
            }
            let submitObj = [];
            let params = [];
            // inspectType 0巡查，1复查
            if (this.inspectType == "0") {
                // 巡查项
                for (let i = 0; i < ins.length; i++) {
                    let inspect = ins[i];
                    let parent = "";
                    if (!inspect.checkResult) {
                        uni.showToast({
                            title: `${inspect.typeName}未巡查!`,
                            icon: "none",
                        });
                        return;
                    } else if (
                        inspect.checkResult == "1" ||
                        inspect.checkResult == "0"
                    ) {
                        // 巡查异常
                        parent = {
                            key: inspect.id,
                            keyName: inspect.typeName,
                            abnormals: [],
                        };
                    }
                    // 子巡查项
                    if (inspect.children && inspect.children.length > 0) {
                        for (let j = 0; j < inspect.children.length; j++) {
                            let item = inspect.children[j];
                            if (!item.checkResultId) {
                                uni.showToast({
                                    title: `${inspect.typeName}-${item.typeName}未巡查!`,
                                    icon: "none",
                                });
                                return;
                            }

                            if (parent) {
                                let contentItem = "";
                                let inspectContents = [];
                                if (item.checkResultId != "normal") {
                                    for (
                                        let k = 0;
                                        k < item.children.length;
                                        k++
                                    ) {
                                        if (
                                            item.checkResultId.indexOf(
                                                item.children[k].id
                                            ) > -1
                                        ) {
                                            contentItem = item.children[k];
                                            inspectContents.push(contentItem);
                                            if (!contentItem.reportWay) {
                                                uni.showToast({
                                                    title: `${inspect.typeName}-${item.typeName}-${contentItem.typeName}上报方式!`,
                                                    icon: "none",
                                                });
                                                return;
                                            }
                                            // 服务端要新增复查任务id add by ray on 2021/01/08
                                            // 余平端要上报复查任务时 eventId设置为空，保留reviewTaskId add by aliang on 2021/08/20
                                            let reviewTaskId = createUUID();
                                            let eventId = contentItem.reportWay=="3"?"":createUUID();

                                            // 需要形成事件上报附件
                                            // 附件必传判断 modify by ray on 2021/04/29
                                            contentItem.eventId = eventId;
                                            contentItem.reviewTaskId = reviewTaskId;
                                                
                                            if (
                                                !contentItem.eventImages ||
                                                contentItem.eventImages
                                                    .length == 0
                                            ) {
                                                uni.showToast({
                                                    title: `请上传${inspect.typeName}-${item.typeName}-${contentItem.typeName}现场图片!`,
                                                    icon: "none",
                                                });
                                                return;
                                            }
                                            let param = {};
                                            param.src = [];
                                            param.bizId = eventId;
                                            param.bizType = "";
                                            param.fileGroup = "";
                                            param.accessToken =
                                            __this.$store.state.loginData.accessToken;
                                            contentItem.eventImages.forEach(
                                                (file) => {
                                                    param.bizType =
                                                        file.bizType;
                                                    param.fileGroup =
                                                        file.fileGroup;
                                                    // if (!param.bizType) {
                                                    //     param.bizType = file.bizType;
                                                    // }
                                                    // if (!param.fileGroup) {
                                                    //     param.fileGroup = file.fileGroup;
                                                    // }
                                                    param.src.push(file.src);
                                                }
                                            );
                                            params.push(param);

                                            if (contentItem.reportWay == "1") {
                                                if (
                                                    !contentItem.eventRectifyImages ||
                                                    contentItem
                                                        .eventRectifyImages
                                                        .length == 0
                                                ) {
                                                    uni.showToast({
                                                        title: `请上传${inspect.typeName}-${item.typeName}-${contentItem.typeName}现场整改后图片!`,
                                                        icon: "none",
                                                    });
                                                    return;
                                                }

                                                param = {};
                                                param.src = [];
                                                // param.bizId = contentItem.eventId;
                                                param.bizId = eventId;
                                                param.bizType = "";
                                                param.fileGroup = "";
                                                param.accessToken =
                                                    __this.$store.state.loginData.accessToken;
                                                contentItem.eventRectifyImages.forEach(
                                                    (file) => {
                                                        param.bizType =
                                                            file.bizType;
                                                        param.fileGroup =
                                                            file.fileGroup;
                                                        // if (!param.bizType) {
                                                        //     param.bizType = file.bizType;
                                                        // }
                                                        // if (!param.fileGroup) {
                                                        //     param.fileGroup = file.fileGroup;
                                                        // }
                                                        param.src.push(
                                                            file.src
                                                        );
                                                    }
                                                );
                                                params.push(param);
                                            }
                                            // 巡查异常
                                            parent.abnormals.push({
                                                dangerTypeCode: item.id,
                                                dangerTypeName: item.typeName,
                                                itemDetailsId: contentItem.id,
                                                // 是否异常
                                                isDanger: "1",
                                                content: contentItem
                                                    ? contentItem.typeName
                                                    : "",
                                                // isReportEvent  是否上报事件 0未上报 1已上报
                                                isReportEvent:
                                                    contentItem &&
                                                    contentItem.reportWay &&
                                                    contentItem.reportWay == "3"
                                                        ? "0"
                                                        : "1",
                                                eventId: eventId,
                                                // // 2.1需求，增加json，暂时不使用
                                                // eventJson: (contentItem && contentItem.eventJson) ? __this.reportEvent(contentItem.eventJson) : "",
                                                // 服务端要新增复查任务id add by ray on 2021/01/08
                                                reviewCheckId: reviewTaskId,
                                                // // 增加事件采集即采即办 add by ray on 2021/01/22
                                                // isMend: (contentItem && contentItem.isMend) ? contentItem.isMend : "0",
                                                // 服务端要求增加reportWay add by ray on 2021/03/10
                                                reportWay:
                                                    contentItem &&
                                                    contentItem.reportWay
                                                        ? contentItem.reportWay
                                                        : "",
                                                remark: contentItem.remark
                                                    ? contentItem.remark
                                                    : "",
                                            });
                                        }
                                    }
                                } else {
                                    // 巡查正常
                                    parent.abnormals.push({
                                        dangerTypeCode: item.id,
                                        dangerTypeName: item.typeName,
                                        itemDetailsId: "",
                                        // 是否异常
                                        isDanger: "0",
                                        content: "",
                                        // isReportEvent  是否上报事件 0未上报 1已上报
                                        isReportEvent: "",
                                        eventId: "",
                                        // // 2.1需求，增加json，暂时不使用
                                        // eventJson: (contentItem && contentItem.eventJson) ? __this.reportEvent(contentItem.eventJson) : "",
                                        // 服务端要新增复查任务id add by ray on 2021/01/08
                                        reviewCheckId: createUUID(),
                                        // // 增加事件采集即采即办 add by ray on 2021/01/22
                                        // isMend: (contentItem && contentItem.isMend) ? contentItem.isMend : "0",
                                        // 服务端要求增加reportWay add by ray on 2021/03/10
                                        reportWay: "",
                                        remark: "",
                                    });
                                }

                                // // 巡查异常
                                // parent.abnormals.push({
                                // 	// // 楼栋或者房屋
                                // 	// objectType: __this.floorInfo.taskType,
                                // 	dangerTypeCode: item.id,
                                // 	dangerTypeName: item.typeName,
                                // 	itemDetailsId: item.checkResultId == "normal" ? "" : item.checkResultId,
                                // 	// 是否异常
                                // 	isDanger: item.checkResultId == "normal" ? "0" : "1",
                                // });
                            }
                        }
                    }
                    if (typeof parent == "object") {
                        submitObj.push(parent);
                    }
                }
            } else if (this.inspectType == "1") {
                // 巡查项
                for (let i = 0; i < ins.length; i++) {
                    let inspect = ins[i];
                    let parent = "";
                    if (!inspect.checkResult) {
                        uni.showToast({
                            title: `${inspect.typeName}未巡查!`,
                            icon: "none",
                        });
                        return;
                    } else if (inspect.checkResult == "1") {
                        // 巡查异常
                        parent = {
                            key: inspect.id,
                            keyName: inspect.typeName,
                            abnormals: [],
                        };
                    }

                    // 子巡查项
                    if (inspect.children && inspect.children.length > 0) {
                        for (let j = 0; j < inspect.children.length; j++) {
                            let item = inspect.children[j];
                            if (parent) {
                                let contentItem = "";
                                for (let k = 0; k < item.children.length; k++) {
                                    if (
                                        item.checkResultId.indexOf(
                                            item.children[k].id
                                        ) > -1
                                    ) {
                                        contentItem = item.children[k];

                                        // children判断，需要移植到for循环
                                        // console.log(item);
                                        // 附件id，修复服务端上报事件无附件问题，附件id不可重复 modify by ray on 2021/01/11
                                        let reviewFileId = createUUID();
                                        if (!contentItem.isReviewChange) {
                                            uni.showToast({
                                                title: `选择${inspect.typeName}-${item.typeName}-${contentItem.typeName}整改!`,
                                                icon: "none",
                                            });
                                            return;
                                        }
                                        if (
                                            !contentItem.imageList ||
                                            contentItem.imageList.length == 0
                                        ) {
                                            uni.showToast({
                                                title: `请上传${inspect.typeName}-${item.typeName}-${contentItem.typeName}现场整改图片!`,
                                                icon: "none",
                                            });
                                            return;
                                        }
                                        let param = {};
                                        param.src = [];
                                        param.bizId = reviewFileId;
                                        param.bizType = "";
                                        param.fileGroup = "";
                                        param.accessToken =
                                            __this.$store.state.loginData.accessToken;
                                        contentItem.imageList.forEach(
                                            (file) => {
                                                param.bizType = file.bizType;
                                                param.fileGroup =
                                                    file.fileGroup;
                                                // if (!param.bizType) {
                                                //     param.bizType = file.bizType;
                                                // }
                                                // if (!param.fileGroup) {
                                                //     param.fileGroup = file.fileGroup;
                                                // }
                                                param.src.push(file.src);
                                            }
                                        );
                                        params.push(param);

                                        // 复查异常
                                        parent.abnormals.push({
                                            // reviewTaskId: __this.roomTaskInfo.id,
                                            // // 服务端要求新增字段
                                            // reviewId: __this.roomTaskInfo.id,
                                            // patrolInfoId: __this.roomTaskInfo.patrolInfoId,
                                            // // 任务id=》原patrolInfoId，服务端要求修改为patrolDetailsId
                                            // detailsId: __this.roomTaskInfo.patrolDetailsId,
                                            // addressCode: __this.roomTaskInfo.addressCode,
                                            // addressName: __this.roomTaskInfo.reviewTaskName,
                                            // dangerAddress: __this.roomTaskInfo.addressName,
                                            // buildingId: __this.roomTaskInfo.buildingId,
                                            // roomId: __this.roomTaskInfo.roomId,
                                            // // 楼栋或者房屋
                                            // objectType: __this.roomTaskInfo.reviewTaskType,
                                            dangerTypeCode: item.id,
                                            dangerTypeName: item.typeName,
                                            content: contentItem
                                                ? contentItem.typeName
                                                : "",
                                            itemDetailsId: contentItem.id,
                                            // // 是否异常
                                            // isDanger: item.checkResultId == "normal" ? "0" : "1",
                                            // // isReportEvent  是否上报事件 0未上报 1已上报
                                            // isReportEvent: (contentItem && contentItem.isReportEvent) ? contentItem.isReportEvent : "0",
                                            // 是否整改
                                            isMend: contentItem.isReviewChange,
                                            fileId: reviewFileId,
                                            // 服务端要新增复查任务id add by ray on 2021/01/08
                                            reviewCheckId:
                                                contentItem.reviewCheckId,
                                            remark: contentItem.remark
                                                ? contentItem.remark
                                                : "",
                                        });
                                    }
                                }
                            }
                        }
                    }
                    if (typeof parent == "object") {
                        submitObj.push(parent);
                    }
                }
            }
            console.log(submitObj);
            console.log(params);
            let returnObject = {
                submitObj: submitObj,
                attachments: params,
            };
            return returnObject;
        },
    },
};
</script>
<style lang="scss" scoped>
.inspect-main {
    .inspect-pop-menu-main {
        margin: 15rpx 30rpx;
        background: #ffffff;
        border-radius: 15rpx;
        padding: 20rpx;

        .inspect-pop-menu-main-menu {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 30rpx;
            color: #666666;
            font-size: 34rpx;
        }

        .inspect-pop-menu-main-menu-bottom {
            border-bottom: 1rpx solid #f6f6f6;
        }
    }

    .inspect-pop-menu-cancel {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 30rpx;
        color: #666666;
        font-size: 34rpx;
        margin: 15rpx 30rpx;
        background: #ffffff;
        border-radius: 15rpx;
    }

    .inspect-container-main {
        width: 100%;
    }

    .inspect-border {
        border: 2rpx solid #4169e1;
        border-radius: 10rpx;
        padding: 2rpx;
    }

    .inspect-main-container {
        padding: 20rpx;
        display: flex;
        width: 100%;
        background-color: #ffffff;
        border-bottom: 1rpx solid #f5f5f5;
        align-items: center;

        .inspect-main-container-title {
            font-size: 32rpx;
            color: #333333;
            flex: 1;
        }

        .inspect-main-container-tip {
            font-size: 28rpx;
            color: #666666;
        }

        .inspect-main-container-tip-exception {
            font-size: 28rpx;
            color: #ff0000;
        }

        .inspect-main-container-icon {
            height: 48rpx;
            width: 48rpx;
            margin-left: 5rpx;
        }
    }

    .inspect-main-container-open {
        background-color: #f6f6f6;
    }

    .inspect-main-container-open-child {
        background-color: #f6f6f6;
        border-bottom: 0rpx solid #e5e5e5;
    }

    .inspect-main-container-content {
        padding: 0 20rpx 0 40rpx;
        width: 100%;
        background-color: #f6f6f6;
    }

    .inspect-check-item {
        padding: 10rpx;
        display: flex;
        // justify-content: center;
        flex-wrap: wrap;
        flex-direction: row;
    }

    .inspect-check-item-content {
        padding: 10rpx 20rpx;
        // border: 1rpx solid #C0C0C0;
        background-color: #dcdcdc;
        border-radius: 15rpx;
        margin: 10rpx;
        display: flex;
        font-size: 26rpx;
        color: #666666;
        align-items: center;
    }

    .inspect-check-item-content-select {
        background-color: #6084e9;
        color: #ffffff;
    }

    .text-area-s {
        background-color: #ffffff;
        border-radius: 10rpx;
        flex: 1;
        width: 90%;
        padding: 15rpx;
        margin: 20rpx;
        height: 160rpx;
    }

    .attachment-container {
        display: flex;
    }

    .attachment {
        padding: 20rpx 10rpx;
        border-bottom: 1rpx solid #f5f5f5;
        margin: 0 10rpx;
        flex: 1;

        .attribute {
            display: flex;

            .asterisk {
                color: #ff0000;
                padding: 0 5rpx;
                width: 30rpx;
            }
        }

        .attachment-area {
            margin-top: 10rpx;
            // padding: 10rpx;
            // border: 0.1rpx solid #cdcdcd;
            border-radius: 5rpx;
            display: flex;
            flex-wrap: wrap;
            flex-direction: row;
            justify-content: flex-start;

            .attachment-area-item-center {
                justify-content: center;
                align-items: center;
                background-color: #f5f5f5;
            }

            .attachment-area-item {
                width: 130rpx;
                height: 130rpx;
                // padding-top: 20rpx;
                // padding-bottom: 20rpx;
                // padding-left: 10rpx;
                // padding-right: 10rpx;
                padding: 5rpx;
                // background-color: #f5f5f5;
                border-radius: 5rpx;
                // border: 0.1rpx solid #cdcdcd;
                margin: 15rpx;
                // align-items: center;
                display: flex;
                // justify-content: center;
                position: relative;

                .image-style {
                    width: 130rpx;
                    height: 130rpx;
                }

                .image-add {
                    width: 48rpx;
                    height: 48rpx;
                }

                .image-delete {
                    position: absolute;
                    z-index: 10;
                    font-size: 18px;
                    color: #ee0a24;
                    width: 48rpx;
                    height: 48rpx;
                    margin-left: 90rpx;
                    margin-top: -20rpx;
                }

                .attachment-area-item-value {
                    font-size: 26rpx;
                    color: #666666;
                    text-align: start;
                }
            }
        }
    }
}
</style>
